﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;

namespace CodeMonkey.EditableObject.Descriptor
{
    public class EditableTypeDescriptorProvider : TypeDescriptionProvider
    {
        private static Dictionary<Type, EditableTypeDescriptor> m_TypeDescriptors = new Dictionary<Type, EditableTypeDescriptor>();

        public override ICustomTypeDescriptor GetTypeDescriptor(Type objectType, object instance)
        {
            if (m_TypeDescriptors.ContainsKey(objectType))
            {
                return m_TypeDescriptors[objectType];
            }
            else
            {
                var descriptor = new EditableTypeDescriptor(objectType, instance); //该instance的添加用于从其中获取EditableContact中;其实是定义在ModelBase<T>中的AllPropertiesInGenericType属性
                m_TypeDescriptors[objectType] = descriptor;
                return descriptor;
            }
        }


    }
}
